package com.baofu.paycore.manager.converter;

import com.alibaba.fastjson.JSONObject;
import com.baofu.paycore.common.enums.FundTypeEnum;
import com.baofu.paycore.dal.model.*;
import com.baofu.paycore.manager.model.*;
import com.baofu.paycore.manager.model.preAuth.PreAuthBO;
import com.baofu.paycore.manager.model.preAuth.SubPreAuthBO;
import com.baofu.paycore.manager.model.withdraw.WithdrawBO;
import com.baofu.paycore.manager.model.withdraw.WithdrawBankBO;
import com.baofu.paycore.manager.model.withdraw.WithdrawFundBO;
import com.baofu.paycore.service.facade.enums.ServiceCodeEnum;
import com.google.common.collect.Lists;
import com.system.commons.utils.BeanCopyUtil;
import org.slf4j.MDC;
import org.slf4j.helpers.SystemMarker;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 对象转换器DO TO BO
 * <p>
 * </p>
 * User: kwl Date: 2016/6/6 ProjectName: paycore Version: 5.0.0
 */
public class DO2BOConverter {

    /**
     * 构建产品退款策略关联信息对象
     *
     * @param refundProductStrategyDO     产品退款策略关联信息对象
     * @param refundStrategyModeDO        统一支付退款模式信息对象
     * @param refundStrategyPriorityDO    退款策略优先级配置信息
     * @return                            产品退款策略关联信息对象
     */
    public static RefundStrategyBO getRefundProductStrategyBO(RefundProductStrategyDO refundProductStrategyDO,
                                                              RefundStrategyModeDO refundStrategyModeDO, RefundStrategyPriorityDO refundStrategyPriorityDO){

        RefundStrategyBO refundStrategyBO = new RefundStrategyBO();
        if(null == refundStrategyModeDO){
            return refundStrategyBO;
        }
        refundStrategyBO.setBizType(refundProductStrategyDO.getBizType());
        refundStrategyBO.setSubBizType(refundProductStrategyDO.getSubBizType());

        refundStrategyBO.setRefundStrategyPriority(refundStrategyPriorityDO.getRefundStrategyPriority());
        refundStrategyBO.setRefundStrategyMode(refundStrategyModeDO.getRefundStrategyMode());
        refundStrategyBO.setRefundTargetMode(refundStrategyModeDO.getRefundTargetMode());

        refundStrategyBO.setPayToolType(refundStrategyPriorityDO.getPayToolType());
        refundStrategyBO.setPriority(Integer.parseInt(refundStrategyPriorityDO.getPriority()));
        return refundStrategyBO;
    }

    /**
     * 构建产品退款策略关联信息对象
     *
     * @param payDO     支付主单DO信息
     * @return          支付主单BO信息
     */
    public static PayBO payDO2BOConverter(PayDO payDO){

        if(null == payDO){
            return null;
        }
        PayBO payBO = new PayBO();

        payBO.setRelationNo(payDO.getRelationNo());
        payBO.setRequestBizNo(payDO.getRequestBizNo());
        payBO.setRequestOrderNo(payDO.getRequestOrderNo());
        payBO.setRequestSystem(payDO.getRequestSystem());
        payBO.setRequestDate(payDO.getRequestDate());
        payBO.setRequestChannel(payDO.getRequestChannel());

        payBO.setPayNo(payDO.getPayNo());
        payBO.setSubBizType(payDO.getSubBizType());
        payBO.setBizType(payDO.getBizType());

        payBO.setPayeeNo(payDO.getPayeeNo());
        payBO.setPayerNo(payDO.getPayerNo());

        payBO.setCcy(payDO.getCcy());
        payBO.setAmt(payDO.getAmt());
        payBO.setRefundAmt(payDO.getRefundAmt());
        payBO.setSourceCcy(payDO.getSourceCcy());
        payBO.setSourceAmt(payDO.getSourceAmt());
        payBO.setRate(payDO.getRate());

        payBO.setEventNo(payDO.getEventNo());
        payBO.setPaymentInfo(payDO.getPaymentInfo());
        payBO.setStatus(payDO.getStatus());
        payBO.setRemark(payDO.getDescription());
        payBO.setOperator(payDO.getCreatedBy());
        payBO.setServiceCode(ServiceCodeEnum.PAY.getCode());
        return payBO;
    }


    /**
     * 构建产品退款策略关联信息对象
     *
     * @param subPayDO     支付子单DO信息
     * @return             支付子单BO信息
     */
    public static SubPayBO subPayDO2BOConverter(SubPayDO subPayDO){

        SubPayBO subPayBO = new SubPayBO();
        if(null == subPayDO){
            return subPayBO;
        }

        subPayBO.setFundDetailNo(subPayDO.getFundDetailNo());
        subPayBO.setPayNo(subPayDO.getPayNo());

        subPayBO.setPayToolType(subPayDO.getPayToolType());
        subPayBO.setPayToolSubType(subPayDO.getPayToolSubType());
        subPayBO.setFundingChannel(subPayDO.getFundChannel());
        subPayBO.setSubFundingChannel(subPayDO.getSubFundChannel());

        subPayBO.setPayerAccNo(subPayDO.getPayerAccNo());
        subPayBO.setPayeeAccNo(subPayDO.getPayeeAccNo());
        subPayBO.setFundType(subPayDO.getFundType());
        subPayBO.setClassType(subPayDO.getClassType());

        subPayBO.setCcy(subPayDO.getCcy());
        subPayBO.setPayToolAmt(subPayDO.getPayToolAmt());
        subPayBO.setFundAmt(subPayDO.getFundAmt());
        subPayBO.setRefundAmount(subPayDO.getRefundAmount());
        subPayBO.setRelateFundDetailNo(subPayDO.getRelateFundDetailNo());

        subPayBO.setStatus(subPayDO.getStatus());

        subPayBO.setEventNo(subPayDO.getEventNo());
        subPayBO.setTransReceiptNo(subPayDO.getTransReceiptNo());
        subPayBO.setTransDate(subPayDO.getTransDate());
        subPayBO.setErrorReason(subPayDO.getErrorReason());
        subPayBO.setErrorCode(subPayDO.getErrorCode());

        subPayBO.setFdDtlExtra(subPayDO.getFdDtlExtra());
        subPayBO.setDescription(subPayDO.getDescription());
        return subPayBO;
    }

    /**
     * 退款订单对象转换 DO to BO
     *
     * @param refundDO    退款订单DO对象
     * @return            退款订单BO对象
     */
    public static RefundBO refundDO2BOConverter(RefundDO refundDO){

        if(null == refundDO) {
            return null;
        }
        RefundBO refundBO = new RefundBO();

        refundBO.setOrigPayNo(refundDO.getOrigPayNo());

        refundBO.setPayNo(refundDO.getPayNo());
        refundBO.setRelationNo(refundDO.getRelationNo());
        refundBO.setRequestBizNo(refundDO.getRequestBizNo());
        refundBO.setRequestOrderNo(refundDO.getRequestOrderNo());
        refundBO.setRequestSystem(refundDO.getRequestSystem());
        refundBO.setRequestDate(refundDO.getRequestDate());
        refundBO.setRequestChannel(refundDO.getRequestChannel());
        refundBO.setServiceCode(refundDO.getServiceCode());

        refundBO.setBizType(refundDO.getBizType());
        refundBO.setSubBizType(refundDO.getSubBizType());
        refundBO.setCcy(refundDO.getCcy());
        refundBO.setAmt(refundDO.getAmt());
        refundBO.setStatus(refundDO.getStatus());
        refundBO.setFeeAmt(refundDO.getFeeAmt());

        refundBO.setCreatedAt(refundDO.getCreatedAt());
        refundBO.setUpdatedAt(refundDO.getUpdatedAt());
        refundBO.setCreatedBy(refundDO.getCreatedBy());
        refundBO.setUpdatedBy(refundDO.getUpdatedBy());
        refundBO.setRefundExtra(refundDO.getRefundExtra());
        refundBO.setDescription(refundDO.getDescription());

        return refundBO;
    }

    /**
     * 退款订单对象转换 DO to BO
     *
     * @param subRefundDO    退款资金单订单DO对象
     * @return               退款资金单订单BO对象
     */
    public static SubRefundBO subRefundDO2BOConverter(SubRefundDO subRefundDO){

        if(null == subRefundDO) {
            return null;
        }
        SubRefundBO subRefundBO = new SubRefundBO();

        subRefundBO.setFundDetailNo(subRefundDO.getFundDetailNo());
        subRefundBO.setPayNo(subRefundDO.getPayNo());
        subRefundBO.setFundType(subRefundDO.getFundType());
        subRefundBO.setClassType(subRefundDO.getClassType());

        subRefundBO.setPayerAccNo(subRefundDO.getPayerAccNo());
        subRefundBO.setPayeeAccNo(subRefundDO.getPayeeAccNo());
        subRefundBO.setFundingChannel(subRefundDO.getFundingChannel());
        subRefundBO.setSubFundingChannel(subRefundDO.getSubFundingChannel());

        subRefundBO.setPayToolType(subRefundDO.getPayToolType());
        subRefundBO.setPayToolSubType(subRefundDO.getPayToolSubType());
        subRefundBO.setEventNo(subRefundDO.getEventNo());
        subRefundBO.setFundBelong(subRefundDO.getFundBelong());

        subRefundBO.setCcy(subRefundDO.getCcy());
        subRefundBO.setAmt(subRefundDO.getAmt());

        subRefundBO.setErrorCode(subRefundDO.getErrorCode());
        subRefundBO.setErrorMsg(subRefundDO.getErrorReason());
        subRefundBO.setTransDate(subRefundDO.getTransDate());
        subRefundBO.setTransReceiptNo(subRefundDO.getTransReceiptNo());

        subRefundBO.setRelateFundDetailNo(subRefundDO.getRelateFundDetailNo());
        subRefundBO.setOrigTransReceiptNo(subRefundDO.getOrigTransReceiptNo());
        subRefundBO.setOrigTransDate(subRefundDO.getOrigTransDate());
        subRefundBO.setOrigRequestBizNo(subRefundDO.getOrigFundDetailNo());

        subRefundBO.setStatus(subRefundDO.getStatus());
        subRefundBO.setDescription(subRefundDO.getDescription());
        subRefundBO.setFdDtlExtra(subRefundDO.getFdDtlExtra());

        return subRefundBO;
    }

    /**
     * 封装充值单信息
     *
     * @param clearDO           充值主单信息
     * @param clearAccountDO    充值资金单信息
     * @param clearBankDO       充值银行单信息
     * @return                  充值单信息
     */
    public static RechargeBO buildRechargeBO(ClearDO clearDO, List<ClearAccountDO> clearAccountDO,
                                             ClearBankDO clearBankDO) {

        RechargeBO rechargeBO = new RechargeBO();
        rechargeBO.setPayNo(clearDO.getPayNo());
        rechargeBO.setAccountNo(clearDO.getAccountNo());
        rechargeBO.setBizType(clearDO.getBizType());
        rechargeBO.setSubBizType(clearDO.getSubBizType());
        rechargeBO.setContractNo(clearDO.getContractNo());
        rechargeBO.setPaymentExt(JSONObject.parseObject(clearDO.getDepositExtra(), Map.class));
        rechargeBO.setPaymentInfo(clearDO.getPaymentInfo());
        rechargeBO.setRequestSystem(clearDO.getRequestSystem());
        rechargeBO.setRequestOrderNo(clearDO.getRequestOrderNo());
        rechargeBO.setRequestBizNo(clearDO.getRequestBizNo());
        rechargeBO.setRequestDate(clearDO.getRequestDate());
        rechargeBO.setRelationNo(clearDO.getRelationNo());

        rechargeBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
        rechargeBO.setCcy(clearDO.getCcy());
        rechargeBO.setAmt(clearDO.getAmt());
        rechargeBO.setStatus(clearDO.getStatus());
        rechargeBO.setServiceCode(clearDO.getServiceCode());
        rechargeBO.setOperator(clearDO.getCreatedBy());

        //充值资金单
        List<RechargeFundBO> rechargeFundBOs = new ArrayList<>();
        for (ClearAccountDO clearAccount : clearAccountDO){
            RechargeFundBO rechargeFundBO = BeanCopyUtil.objConvert(clearAccount, RechargeFundBO.class);
            rechargeFundBOs.add(rechargeFundBO);
        }
        rechargeBO.setRechargeFundBO(rechargeFundBOs);

        //充值银行单
        if(!Objects.isNull(clearBankDO)) {
            RechargeBankBO rechargeBankBO = BeanCopyUtil.objConvert(clearBankDO, RechargeBankBO.class);
            rechargeBO.setRechargeBankBO(rechargeBankBO);
        }
        return rechargeBO;
    }

    /**
     * 封装转账单信息
     *
     * @param transferDO    转账单
     * @param list          子转账单
     * @return              转账信息单
     */
    public static TransferBO buildTransferBO(TransferDO transferDO, List<SubTransferDO> list) {
        TransferBO transferBO = new TransferBO();
        transferBO.setOldPayNo(transferDO.getOldPayNo());
        transferBO.setServiceCode(transferDO.getServiceCode());
        transferBO.setEventNo(transferDO.getEventNo());
        transferBO.setBizChargeAmt(transferDO.getBizChargeAmt());
        transferBO.setBizFeeAccount(transferDO.getBizFeeAccount());
        transferBO.setPayNo(transferDO.getPayNo());
        transferBO.setRelationNo(transferDO.getRelationNo());
        transferBO.setBizType(transferDO.getBizType());
        transferBO.setSubBizType(transferDO.getSubBizType());
        transferBO.setRequestBizNo(transferDO.getRequestBizNo());
        transferBO.setRequestOrderNo(transferDO.getRequestOrderNo());
        transferBO.setRequestDate(transferDO.getRequestDate());
        transferBO.setRequestSystem(transferDO.getRequestSystem());
        transferBO.setAmt(transferDO.getAmt());
        transferBO.setCcy(transferDO.getCcy());
        transferBO.setStatus(transferDO.getStatus());
        transferBO.setRequestChannel(transferDO.getRequestChannel());
        transferBO.setEventNo(transferDO.getEventNo());
        transferBO.setOperator(transferDO.getCreatedBy());
        transferBO.setDescription(transferDO.getDescription());
        transferBO.setSubTransferDO(list);

        return transferBO;
    }

    /**
     * 获取提现资金单
     *
     * @param clearAccountDO    子单
     * @return                  WithdrawFundBO
     */
    public static WithdrawFundBO getWithdrawFundBO(ClearAccountDO clearAccountDO) {
        if (clearAccountDO == null) {
            return null;
        }
        WithdrawFundBO withdrawFundBO = new WithdrawFundBO();
        withdrawFundBO.setFundDetailNo(clearAccountDO.getFundDetailNo());
        withdrawFundBO.setPayNo(clearAccountDO.getPayNo());
        withdrawFundBO.setFundType(clearAccountDO.getFundType());
        withdrawFundBO.setPayToolType(clearAccountDO.getPayToolType());
        withdrawFundBO.setPayToolSubType(clearAccountDO.getPayToolSubType());
        withdrawFundBO.setAmt(clearAccountDO.getAmt());
        withdrawFundBO.setReqAccAmt(clearAccountDO.getReqAccAmt());
        withdrawFundBO.setBizFeeAccount(clearAccountDO.getBizFeeAccount());
        withdrawFundBO.setCcy(clearAccountDO.getCcy());
        withdrawFundBO.setStatus(clearAccountDO.getStatus());
        withdrawFundBO.setAccountNo(clearAccountDO.getAccountNo());
        withdrawFundBO.setFreezeCode(clearAccountDO.getFreezeCode());
        withdrawFundBO.setTransDate(clearAccountDO.getTransDate());
        withdrawFundBO.setErrorCode(clearAccountDO.getErrorCode());
        withdrawFundBO.setErrorReason(clearAccountDO.getErrorReason());
        withdrawFundBO.setFundChannel(clearAccountDO.getFundChannel());
        withdrawFundBO.setEventNo(clearAccountDO.getEventNo());
        withdrawFundBO.setUnfreezeNo(clearAccountDO.getUnfreezeNo());
        withdrawFundBO.setTransReceiptNo(clearAccountDO.getTransReceiptNo());
        return withdrawFundBO;
    }

    /**
     * 提现资金单集合
     *
     * @param clearAccountDOs   子单
     * @return                  资金单集合
     */
    public static List<WithdrawFundBO> getWithdrawFundBOList(List<ClearAccountDO> clearAccountDOs){
        if (CollectionUtils.isEmpty(clearAccountDOs)){
            return null;
        }
        List<WithdrawFundBO> list = Lists.newArrayList();
        clearAccountDOs.forEach((clearAccountDO -> list.add(getWithdrawFundBO(clearAccountDO))));
        return list;
    }

    /**
     * 获取提现银行单BO信息
     *
     * @param clearBankDO   银行单DO
     * @return              WithdrawBankBO
     */
    public static WithdrawBankBO getWithdrawBankBO(ClearBankDO clearBankDO) {

        if (clearBankDO == null) {
            return null;
        }
        WithdrawBankBO withdrawBankBO = new WithdrawBankBO();
        withdrawBankBO.setFundDetailNo(clearBankDO.getFundDetailNo());
        withdrawBankBO.setPayNo(clearBankDO.getPayNo());
        withdrawBankBO.setPayToolType(clearBankDO.getPayToolType());
        withdrawBankBO.setPayToolSubType(clearBankDO.getPayToolSubType());
        withdrawBankBO.setCcy(clearBankDO.getCcy());
        withdrawBankBO.setAmt(clearBankDO.getAmt());
        withdrawBankBO.setStatus(clearBankDO.getStatus());
        withdrawBankBO.setBankCode(clearBankDO.getBankCode());
        withdrawBankBO.setTransReceiptNo(clearBankDO.getTransReceiptNo());
        withdrawBankBO.setTransDate(clearBankDO.getTransDate());
        withdrawBankBO.setErrorCode(clearBankDO.getErrorCode());
        withdrawBankBO.setErrorReason(clearBankDO.getErrorReason());
        withdrawBankBO.setFundChannel(clearBankDO.getFundChannel());
        withdrawBankBO.setContractNo(clearBankDO.getContractNo());
        withdrawBankBO.setAgreeRelId(clearBankDO.getAgreeRelId());
        withdrawBankBO.setAgreementNo(clearBankDO.getAgreementNo());
        withdrawBankBO.setDescription(clearBankDO.getDescription());
        return withdrawBankBO;
    }

    /**
     * 获取提现单信息
     *
     * @param clearDO   提现单DO
     * @return          WithdrawBO
     */
    public static WithdrawBO getWithdrawBO(ClearDO clearDO) {
        if (clearDO == null) {
            return null;
        }
        WithdrawBO withdrawBO = new WithdrawBO();
        withdrawBO.setPayNo(clearDO.getPayNo());
        withdrawBO.setRequestBizNo(clearDO.getRequestBizNo());
        withdrawBO.setRequestOrderNo(clearDO.getRequestOrderNo());
        withdrawBO.setRequestSystem(clearDO.getRequestSystem());
        withdrawBO.setRequestDate(clearDO.getRequestDate());
        withdrawBO.setRequestChannel(clearDO.getRequestChannel());
        withdrawBO.setServiceCode(clearDO.getServiceCode());
        withdrawBO.setBizType(clearDO.getBizType());
        withdrawBO.setSubBizType(clearDO.getSubBizType());
        withdrawBO.setAccountNo(clearDO.getAccountNo());
        withdrawBO.setCcy(clearDO.getCcy());
        withdrawBO.setAmt(clearDO.getAmt());
        withdrawBO.setStatus(clearDO.getStatus());
        withdrawBO.setContractNo(clearDO.getContractNo());
        withdrawBO.setMerchantNo(clearDO.getMerchantNo());
        withdrawBO.setPaymentInfo(clearDO.getPaymentInfo());
        withdrawBO.setDescription(clearDO.getDescription());

        return withdrawBO;
    }

    /**
     * 充值DO转换BO
     *
     * @param clearDO   充值DO
     * @return          充值BO
     */
    public static RechargeBO getRechargeBOByDO(ClearDO clearDO) {

        if (clearDO == null) {
            return null;
        }
        RechargeBO rechargeBO = new RechargeBO();
        rechargeBO.setPayNo(clearDO.getPayNo());
        rechargeBO.setRequestBizNo(clearDO.getRequestBizNo());
        rechargeBO.setRequestOrderNo(clearDO.getRequestOrderNo());
        rechargeBO.setRequestSystem(clearDO.getRequestSystem());
        rechargeBO.setRequestDate(clearDO.getRequestDate());
        rechargeBO.setRequestChannel(clearDO.getRequestChannel());
        rechargeBO.setServiceCode(clearDO.getServiceCode());
        rechargeBO.setBizType(clearDO.getBizType());
        rechargeBO.setSubBizType(clearDO.getSubBizType());
        rechargeBO.setAccountNo(clearDO.getAccountNo());
        rechargeBO.setCcy(clearDO.getCcy());
        rechargeBO.setAmt(clearDO.getAmt());
        rechargeBO.setStatus(clearDO.getStatus());
        rechargeBO.setContractNo(clearDO.getContractNo());
        rechargeBO.setMerchantNo(clearDO.getMerchantNo());
        rechargeBO.setPaymentInfo(clearDO.getPaymentInfo());
        rechargeBO.setDescription(clearDO.getDescription());

        return rechargeBO;
    }

    /**
     * 预授权DO对象转换BO对象
     *
     * @param preAuthDO     预授权DO对象
     * @return              预授权BO对象
     */
    public static PreAuthBO preAuthDO2BOConverter(PreAuthDO preAuthDO) {
        if (preAuthDO == null) {
            return null;
        }
        PreAuthBO preAuthBO = new PreAuthBO();
        preAuthBO.setRequestBizNo(preAuthDO.getRequestBizNo());
        preAuthBO.setRequestOrderNo(preAuthDO.getRequestOrderNo());
        preAuthBO.setPayNo(preAuthDO.getPayNo());
        preAuthBO.setRequestDate(preAuthDO.getRequestDate());
        preAuthBO.setPayerNo(preAuthDO.getPayerNo());
        preAuthBO.setAmt(preAuthDO.getAmt());
        preAuthBO.setCcy(preAuthDO.getCcy());
        preAuthBO.setRequestSystem(preAuthDO.getRequestSystem());
        preAuthBO.setRequestChannel(preAuthDO.getRequestChannel());
        preAuthBO.setServiceCode(preAuthDO.getServiceCode());
        preAuthBO.setStatus(preAuthDO.getStatus());
        preAuthBO.setBizType(preAuthDO.getBizType());
        preAuthBO.setSubBizType(preAuthDO.getSubBizType());
        preAuthBO.setOrigPayNo(preAuthDO.getOrigPayNo());
        preAuthBO.setDealAmt(preAuthDO.getDealAmt());
        preAuthBO.setDepositExtra(preAuthDO.getDepositExtra());
        preAuthBO.setDescription(preAuthDO.getDescription());
        preAuthBO.setRelationNo(preAuthDO.getRelationNo());
        preAuthBO.setOperator(preAuthDO.getCreatedBy());

        return preAuthBO;
    }

    /**
     * 预授权资金单DO对象转换BO对象
     *
     * @param subPreAuthDO      预授权资金单DO对象
     * @return                  预授权资金单BO对象
     */
    public static SubPreAuthBO subPreAuthDO2BOConverter(SubPreAuthDO subPreAuthDO) {
        if (subPreAuthDO == null) {
            return null;
        }
        SubPreAuthBO subPreAuthBO = new SubPreAuthBO();
        subPreAuthBO.setFundDetailNo(subPreAuthDO.getFundDetailNo());
        subPreAuthBO.setFundType(subPreAuthDO.getFundType());
        subPreAuthBO.setPayNo(subPreAuthDO.getPayNo());
        subPreAuthBO.setPayToolType(subPreAuthDO.getPayToolType());
        subPreAuthBO.setPayToolSubType(subPreAuthDO.getPayToolSubType());
        subPreAuthBO.setFundingChannel(subPreAuthDO.getFundingChannel());
        subPreAuthBO.setSubFundingChannel(subPreAuthDO.getSubFundingChannel());
        subPreAuthBO.setPayerAccNo(subPreAuthDO.getPayerAccNo());
        subPreAuthBO.setPayeeAccNo(subPreAuthDO.getPayeeAccNo());
        subPreAuthBO.setAmt(subPreAuthDO.getAmt());
        subPreAuthBO.setCcy(subPreAuthDO.getCcy());
        subPreAuthBO.setRelateFundDetailNo(subPreAuthDO.getRelateFundDetailNo());
        subPreAuthBO.setStatus(subPreAuthDO.getStatus());
        subPreAuthBO.setEventNo(subPreAuthDO.getEventNo());
        subPreAuthBO.setTransReceiptNo(subPreAuthDO.getTransReceiptNo());
        subPreAuthBO.setFreezeCode(subPreAuthDO.getFreezeCode());
        subPreAuthBO.setFreezeNo(subPreAuthDO.getFreezeNo());
        subPreAuthBO.setFdDtlExtra(subPreAuthDO.getFdDtlExtra());
        subPreAuthBO.setUnfreezeReceiptNo(subPreAuthDO.getUnfreezeReceiptNo());
        subPreAuthBO.setTransDate(subPreAuthDO.getTransDate());
        subPreAuthBO.setErrorCode(subPreAuthDO.getErrorCode());
        subPreAuthBO.setErrorReason(subPreAuthDO.getErrorReason());
        subPreAuthBO.setDescription(subPreAuthDO.getDescription());

        return subPreAuthBO;
    }

    public static PayBO buildPayBO(PayDO payDO, List<SubPayDO> subPayDOs){

        PayBO payBO = payDO2BOConverter(payDO);
        List<SubPayBO> subPayBOs = Lists.newArrayList();
        subPayDOs.forEach(subPayDO -> subPayBOs.add(subPayDO2BOConverter(subPayDO)));
        payBO.setSubPayList(subPayBOs);

        return payBO;
    }

    /**
     * 获取提现资金单
     *
     * @param freezeDO    冻结单
     * @return                  WithdrawFundBO
     */
    public static WithdrawFundBO getFreezeFundBO(FreezeDO freezeDO) {
        if (freezeDO == null) {
            return null;
        }
        WithdrawFundBO withdrawFundBO = new WithdrawFundBO();
        withdrawFundBO.setFundDetailNo(freezeDO.getFreezeNo());
        withdrawFundBO.setPayNo(freezeDO.getPayNo());
        withdrawFundBO.setFundType(FundTypeEnum.WITHDRAW_FREEZE.getCode());
        withdrawFundBO.setAmt(freezeDO.getAmt());
        withdrawFundBO.setReqAccAmt(freezeDO.getAmt());
        withdrawFundBO.setBizFeeAccount(freezeDO.getAccountNo());
        withdrawFundBO.setCcy(freezeDO.getCcy());
        withdrawFundBO.setStatus(freezeDO.getStatus());
        withdrawFundBO.setAccountNo(freezeDO.getAccountNo());
        withdrawFundBO.setFreezeCode(freezeDO.getFreezeCode());
        withdrawFundBO.setTransDate(freezeDO.getTransDate());
        withdrawFundBO.setErrorCode(freezeDO.getErrorCode());
        withdrawFundBO.setErrorReason(freezeDO.getErrorReason());
        withdrawFundBO.setTransReceiptNo(freezeDO.getTransDeceiptNo());
        return withdrawFundBO;
    }
}
